#include "science.h"
#include "stralgo.h"
#include "stralgo_s.h"
#include <iostream>
using std::cout;
using std::endl;
string factorial(const string &f)
{
	string ans = "1";
	string i = "2";
	unsigned int len = f.length();
	while ((i.length() < len) || 
		((i.length() == len) && (i <= f)))
	{
		ans = Multiply(ans, i);
		i = Plus(i, "1");
	}
	return ans;
}

string Exp(const string &x)
{
	string i = "1";
	string fac = "1";
	string xn = "1";
	string ans = "1";
	int times = 100;
	while (times--)
	{
		xn = Multiply_s(xn, x);
		fac = Multiply(fac, i);
		ans = Plus_s(ans, Divide_s(xn, fac));
		i = Plus(i, "1");
	}
	return ans;
}


string sin(const string &x)
{
	string i = "2";
	string fac = "1";
	string xn = x;
	string ans = x;
	int isNeg = 1;
	int times = 101;
	while (times--)
	{
		fac = Multiply(fac, i);
		xn = Multiply_s(xn, x);
		i = Plus(i, "1");
		fac = Multiply(fac, i);
		xn = Multiply_s(xn, x);
		//cout << ans << endl;
		string fn = Divide_s(xn, fac);
		
		if (isNeg)
		{
			ans = Reduce_s(ans, fn);
			//cout << "- ";
		} 
		else
		{
			ans = Plus_s(ans, fn);
			//cout << "+ ";
		}
		//cout << fn << endl;
		i = Plus(i, "1");
		isNeg ^= 1;
	}
	return ans;
}


string cos(const string &x)
{
	string fac = "1";
	string i = "1";
	string xn = "1";
	string ans = "1";
	int isNeg = 1;
	int times = 101;
	while (times--)
	{
		fac = Multiply(fac, i);
		xn = Multiply_s(xn, x);
		i = Plus(i, "1");
		fac = Multiply(fac, i);
		xn = Multiply_s(xn, x);
		string fn = Divide_s(xn, fac);
		if (isNeg)
		{
			ans = Reduce_s(ans, fn);
		} 
		else
		{
			ans = Plus_s(ans, fn);
		}
		isNeg ^= 1;
		i = Plus(i, "1");
	}
	return ans;
}

